package com.cmbc.xiaodu.balance;

import com.baidu.dueros.bot.BaseBot;
import com.baidu.dueros.certificate.Certificate;
import com.baidu.dueros.data.request.permission.event.PermissionGrantFailedEvent;
import com.baidu.dueros.data.request.permission.event.PermissionGrantedEvent;
import com.baidu.dueros.data.response.OutputSpeech;
import com.baidu.dueros.model.Request;
import com.baidu.dueros.model.Response;
import com.fasterxml.jackson.databind.JsonMappingException;

import javax.servlet.http.HttpServletRequest;
import java.io.IOException;

public class MinPermissionBot extends BaseBot {



    /**
     * 处理表示用户拒绝授权事件 对应的事件是：Permission.GrantFailed
     *
     * @param permissionGrantFailedEvent
     *            表示用户拒绝授权
     * @return Response 返回的Response
     */
    @Override
    protected Response onPermissionGrantFailedEvent(PermissionGrantFailedEvent permissionGrantFailedEvent) {
        OutputSpeech outputSpeech = new OutputSpeech(OutputSpeech.SpeechType.PlainText, "授权失败");
        // 构造返回的Response
        setExpectSpeech(true);
        Response response = new Response(outputSpeech);
        return response;
    }

    /**
     * 处理表示用户同意授权事件 对应的事件是：Permission.Granted
     *
     * @param permissionGrantedEvent
     *            表示用户同意授权
     * @return Response 返回的Response
     */
    @Override
    protected Response onPermissionGrantedEvent(PermissionGrantedEvent permissionGrantedEvent) {
        OutputSpeech outputSpeech = new OutputSpeech(OutputSpeech.SpeechType.PlainText, "授权成功");
        // 构造返回的Response
        setExpectSpeech(true);
        Response response = new Response(outputSpeech);
        return response;
    }


    protected MinPermissionBot(Request request) throws IOException {
        super(request);
    }

    protected MinPermissionBot(String request) throws IOException, JsonMappingException {
        super(request);
    }

    protected MinPermissionBot(Certificate certificate) throws IOException {
        super(certificate);
    }

    protected MinPermissionBot(HttpServletRequest request) throws IOException, JsonMappingException {
        super(request);
    }
}
